﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="AddDonThu.ascx.cs" Inherits="CMS.Web.CompDenu.AddDonThu" %>
<%@ Import Namespace="System.Collections" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="CMS.Core.DataInterfaces" %>
<%@ Import Namespace="CMS.Core.Domain" %>
<head>    
    <style>
        .Upload{width:350px}
    </style>
</head>

<center>
<table width="96%" class="Table_Border" align="center" style="border-collapse: collapse" cellSpacing="0" cellPadding="0" border="0">
    <tr><td valign="middle" align="center" height="50px"><span id="lblTitle" runat="server" class="Title">CẬP NHẬT ĐƠN THƯ</span></td>
    </tr>    
    <tr id="rowMess" runat="server">
        <td valign="middle" align="left" height="30px">
            <span id="lblMess" runat="server" class="Grid_Error"></span>
        </td>
    </tr>    
    <tr>
        <td width="100%" valign=top align=center>
        <div style="border:1px solid #0b73f4;width:100%;height:atuo;">
			<table id="tblNew" class="Table_Border" style="border-collapse: collapse" cellspacing="2" cellpadding="0" width="99%" align="center" border="0">
                <tr>
		            <td class="Col_Left" width="21%">Số thụ lý <FONT color="#ff0000">(*)</FONT>:</TD>
			        <td class="Col_Right" width="20%">
			        	<asp:textbox id="txtSoThuLy" runat="server" CssClass="TextBox" Width="90%" MaxLength="20"></asp:textbox>
                    </td>
                    <td class="" width="14%" style="text-align:right; font-weight:bold;">Đơn đề ngày:</TD>
			        <td class="Col_Right" width="16%">
			        	<asp:textbox id="txtDonDeNgay" UNSELECTABLE="on" runat="server" CssClass="TextBox" Width="75%" MaxLength="10" Enabled="true"></asp:textbox>
			        	&nbsp;<img align="absmiddle" style="width:13px;cursor:pointer;" id="imgDonDeNgay" src="Images/icon.gif" alt="" />
                    </td>
					<td class="Col_Left" width="14%">Ngày nhận <FONT color="#ff0000">(*)</FONT>:</TD>
			        <td class="Col_Right" width="15%">
			        	<asp:textbox id="txtNgayGui" UNSELECTABLE="on" runat="server" CssClass="TextBox" Width="74%" MaxLength="10" Enabled="true"></asp:textbox>
			        	&nbsp;<img align="absmiddle" style="width:13px;cursor:pointer;" id="imgNgayGui" src="Images/icon.gif" alt="" />
                    </td>
                </tr>
                <tr>
		            <td class="Col_Left">Họ và tên <FONT color="#ff0000">(*):</FONT></TD>
			        <td class="Col_Right" colspan="2">
                        <asp:textbox id="txtHoTen" runat="server" CssClass="TextBox" Width="100%" MaxLength="200"></asp:textbox>
                    </td>
                    <td class="Col_Left" style="text-align:right;">Lần gửi <FONT color="#ff0000">(*):</TD>
			        <td class="Col_Right" colspan="2">
			        	<asp:textbox id="txtLanGui" runat="server" CssClass="TextBox" Width="99%" MaxLength="2"></asp:textbox>
                    </td>
                </tr>
                <tr>
		            <td class="Col_Left">Địa chỉ <FONT color="#ff0000">(*):</TD>
			        <td class="Col_Right" colspan="2">
                        <asp:textbox id="txtDiaChi" runat="server" CssClass="TextBox" Width="100%" MaxLength="512"></asp:textbox>
                    </td>
                    <td class="Col_Left" style="text-align:right;">Địa bàn <FONT color="#ff0000">(*)</FONT>:</TD>
			        <td class="Col_Right" colspan="2">
			            <asp:textbox id="drpDiaBan" runat="server" CssClass="TextBox" Width="90%" MaxLength="250"></asp:textbox>
			            <img src="Images/scroll2.png" style="display:; cursor: pointer; cursor: hand;" onclick="openSelectDiaBanWindow('<% =drpDiaBan.ClientID%>','<%=hidDiaBan.ClientID %>');" />
			            <asp:HiddenField ID="hidDiaBan" runat="server" />
			        </td>
                </tr>
                <tr>
		            <td class="Col_Left">Loại đơn:</TD>
			        <td class="Col_Right" colspan="2">
			        	<asp:DropDownList ID="drpLoaiDon" runat="server" CssClass="ListBox" Width="99%" DataTextField="TenLoaiDon" DataValueField="ID"></asp:DropDownList>
                    </td>
                    <td class="Col_Left" style="text-align:right;">Lĩnh vực:</TD>
			        <td class="Col_Right" colspan="2">
			        	<asp:DropDownList ID="drpLinhVuc" runat="server" CssClass="ListBox" Width="100%" DataTextField="TenLinhVuc" DataValueField="ID"></asp:DropDownList>
                    </td>
                </tr>
				<tr>
		            <td class="Col_Left">Đồng gửi:</TD>
			        <td class="Col_Right" colspan="2">
                        <asp:textbox id="txtDongGui" runat="server" CssClass="TextBox" Width="99%" MaxLength="50"></asp:textbox>
                    </td>
                    <td colspan="3" style="display: none;">
                        <asp:DropDownList ID="drpLoaiPhieu" runat="server" CssClass="ListBox" Width="99%">
                            <asp:ListItem Selected>Phiếu tr&#236;nh</asp:ListItem>
                            <asp:ListItem>Phiếu chuyển</asp:ListItem>
                            <asp:ListItem>C&#244;ng văn giải quyết</asp:ListItem>
                            <asp:ListItem>Văn bản &#225;p dụng</asp:ListItem>
                        </asp:DropDownList>
                    </td>
                </tr>
                <tr>
		            <td class="Col_Left">Tóm tắt nội dung  <FONT color="#ff0000">(*):</TD>
			        <td class="Col_Right" colspan="5">
                        <asp:textbox id="txtTomTat" Runat="server" TextMode=MultiLine Rows="2" Width="99%" CssClass="TextArea"></asp:textbox>
                    </td>
                </tr>
                <tr valign="top">
		            <td class="Col_Left">Đề xuất ý kiến:</TD>
			        <td class="Col_Right" colspan="2" valign="top">
			            <asp:textbox id="txtDeXuatYKien" Runat="server" TextMode=MultiLine Rows="3" Width="99%" CssClass="TextArea"></asp:textbox>
                    </td>
                    <td class="Col_Left" style="text-align:right;">Văn bản đính kèm:<br />
                        <table width="100%" border="0" cellpadding="0" cellspacing="0">
                            <tr>
                                <td style="height:30px; vertical-align: bottom; text-align: right;">
                                    <img border="0" alt="Thêm v&#259;n b&#7843;n" src="Images/file_add.gif" style="cursor: pointer; cursor: hand;" onclick="addFile();"/>
                                    <img border="0" alt="Xóa v&#259;n b&#7843;n" src="Images/file_delete.gif" style="cursor: pointer; cursor: hand;" onclick="removeFile();"/>
                                </td>
                            </tr>
                        </table>
                    </td>
			        <td class="Col_Right" colspan="2">
			        	<table id="tblFiles" border="0" width="100%" cellpadding="0" cellspacing="0" style="border-collapse: collapse;">
                            <tbody id="files_body">
                            <%if (DonThuToEdit != null)
                              {
                                  foreach (FileDinhKem fdk in DonThuToEdit.FileDinhKems)
                                  {%>
                                    <tr id="files_pattern<%=fdk.ID%>" style="display:;" class="Row_Normal">
                                        <td align="center"></td>
                                        <td id="files_name<%=fdk.ID%>" style="padding-left: 5px;" width="94%" valign="middle">
                                            <a href="download.aspx?fileName=<%=fdk.TenFileDinhKem%>" class="DownloadLink"><%=fdk.TenFileDinhKem%></a>&nbsp;
                                            <img id="img1" border="0" src="Images/Icon_Del.gif" onclick="deleteFile('<%=fdk.ID%>');" style="cursor: pointer; cursor: hand;">
                                        </td>
                                        <td align="center"></td>
                                    </tr>
                                <%}
                              }%>
                            </tbody>
                        </table>
			            <asp:FileUpload ID="fUpload1" runat="server" Width="99%" CssClass="TextFile" />
                        <asp:FileUpload ID="fUpload2" runat="server" Width="99%" CssClass="TextFile" Style="display: none;" />
                        <asp:FileUpload ID="fUpload3" runat="server" Width="99%" CssClass="TextFile" Style="display: none" />
                        <asp:FileUpload ID="fUpload4" runat="server" Width="99%" CssClass="TextFile" Style="display: none" />
                        <asp:FileUpload ID="fUpload5" runat="server" Width="99%" CssClass="TextFile" Style="display: none" />
                        <asp:HiddenField ID="hidFileDinhKem" runat="server" />
                    </td>
                </tr>
                <!--
                <tr>
		            <td class="Col_Left">Người xử lý:</TD>
			        <td class="Col_Right" colspan="5">drpNguoiXuLy
                    </td>
                </tr>
                -->
				<tr>
		            <td class="Col_Left">Ý kiến của lãnh đạo 1:</TD>
			        <td class="Col_Right" colspan="2">
                        <asp:textbox id="txtYKienLDVP" Runat="server" TextMode=MultiLine Rows="3" Width="99%" CssClass="TextArea"></asp:textbox>
                    </td>
                    <td class="Col_Left" style="text-align:right;">Văn bản chỉ đạo:</TD>
			        <td class="Col_Right" colspan="2">
			        	<asp:ListBox ID="drpVBCD" runat="server" Rows="3" CssClass="ListBox" Width="90%" DataTextField="TenVanBan" DataValueField="ID"></asp:ListBox>
                        <img src="Images/scroll2.png" style="cursor: pointer; cursor: hand;" onclick="openSelectPersonsWindow('<%=drpVBCD.ClientID%>','<%=hidVBCD.ClientID %>');" />
                        <asp:HiddenField ID="hidVBCD" runat="server" />
                    </td>
                </tr>
				<tr>
		            <td class="Col_Left">Ý kiến của lãnh đạo 2:</TD>
			        <td class="Col_Right" colspan="2">
                        <asp:textbox id="txtYKienLDUBND" Runat="server" TextMode=MultiLine Rows="3" Width="99%" CssClass="TextArea"></asp:textbox>
                    </td>
                    <td class="Col_Left" style="text-align:right;">Kết quả giải quyết:</TD>
			        <td class="Col_Right" colspan="2">
                        <asp:textbox id="txtKetQuaGiaiQuyet" Runat="server" TextMode=MultiLine Rows="3" Width="99%" CssClass="TextArea"></asp:textbox>
                    </td>
                </tr>
				<tr>
		            <td class="Col_Left">
                        Tình trạng hồ sơ:</TD>
			        <td class="Col_Right" colspan="2">
			            <asp:DropDownList ID="drpTTXL" runat="server" CssClass="ListBox" Width="100%" DataTextField="TenTTXL" DataValueField="ID"></asp:DropDownList>
                    </td>
                    <td class="Col_Left" style="text-align:right;">Trạng thái:</TD>
					<td class="Col_Right" colspan="2">
                        <asp:radiobuttonlist id="radStatus" Runat="server" CssClass="Col_Right" RepeatDirection="Horizontal" RepeatColumns="2" width="95%">
						    <ASP:LISTITEM Selected="True" Value="true">Hoạt động</ASP:LISTITEM>
						    <ASP:LISTITEM Value="false">Không hoạt động</ASP:LISTITEM>
					    </asp:radiobuttonlist>
                    </td>
                </tr>
                 </table>
            </div>
            <table style="border-collapse: collapse" cellspacing="0" cellpadding="0" width="100%" align="center" border="0">
				<tr>
				    <td height="40" align="left" style="width:70%;">
                        <input type="button" class="Button" onclick="OpenPrinter(0);" value="In phiếu trình" id="Button1" />
                        <input type="button" class="Button" onclick="OpenPrinter(1);" value="In phiếu chuyển" />
                        <input type="button" class="Button" onclick="OpenPrinter(2);" value="Công văn GQ" />                        
                        <asp:button style="display:none" id="btnOK" runat="server" CssClass="Button" Text="Cập nhật" OnClick="btnOK_Click"></asp:button>
                        <asp:button style="display:none" id="btnOKC" runat="server" CssClass="Button" Text="C&#7853;p nh&#7853;t và ti&#7871;p t&#7909;c" OnClick="btnOKC_Click"></asp:button>
                    </td>
                    <td align="right">
                        <asp:HiddenField ID="hidNguoiNhan" runat="server" />
                        <asp:HiddenField ID="hidNguoiXuLy" runat="server" />
                        <asp:HiddenField ID="hidNguoiChuyen" runat="server" />
                        <input type="button" class="Button" onclick="CheckInput('<%=ID%>');" value="  Lưu lại  " id="Button2" />
                        <input type="reset" class="Button" value="Nhập lại" id="btnReset" />
                    </td>
				</tr>
	        </table>
		</td><!--CheckInput_callback()-->
    </tr>
</table>
</center>
<script language="javascript">

    var hidFDK = document.getElementById("<%=hidFileDinhKem.ClientID %>");
    
    var _currentDate = "<%=DateTime.Now.ToString("dd/MM/yyyy") %>";
    var calDonDeNgay = new Zapatec.Calendar({lang: "vn", inputField: "<%=txtDonDeNgay.ClientID %>", 
        ifFormat: "%d/%m/%Y", button: "imgDonDeNgay", theme: "aqua"});
    var calNgayGui = new Zapatec.Calendar({lang: "vn", inputField: "<%=txtNgayGui.ClientID %>", 
        ifFormat: "%d/%m/%Y", button: "imgNgayGui", theme: "aqua"});

    function removeListId(src, id){
        var result = src;
        result = (','+ result).replace(','+id,'');
        if(result.length>2){
            result = result.substr(1);    
        }else{
            result = '';
        }
        return result;
    }
                
    function deleteFile(fileId){
        var row = document.getElementById('files_pattern'+fileId);
        document.getElementById('files_body').deleteRow(row.sectionRowIndex);
        hidFDK.value = removeListId(hidFDK.value,fileId);
    }
    
    var fIndex = 1;
    function addFile(){
        if(fIndex<5){
            fIndex ++;
            var fUploadId = "<%=fUpload1.ClientID%>";
            document.getElementById(fUploadId.replace('Upload1','Upload'+fIndex)).style.display = '';
        }
    }

    function removeFile(){
        if(fIndex>1){
            var fUploadId = "<%=fUpload1.ClientID%>";
            document.getElementById(fUploadId.replace('Upload1','Upload'+fIndex)).style.display = 'none';
            fIndex --;
        }
    }
    
    function CheckInput(ID){
        CMS.Presenters.Presenters.AddDonThuPresenter.isSameName($("#<%=txtHoTen.ClientID %>").val(), ID, CheckInput_callback);
    }
    
    function CheckInput_callback(res){        
        strMsg = "";
        valDongGui = $("#<%=txtDongGui.ClientID %>").val();
        strMsg += isValid("<%=txtSoThuLy.ClientID %>",6,1,number,0,0,"Số thụ lý");
        var firstChar = document.getElementById("<%=txtHoTen.ClientID %>").value;
        firstChar = firstChar.substring(0, 1);
        if (res.value && $("#<%=txtHoTen.ClientID %>").val() != ""){
            strMsg += "\n - Họ và tên này đã được đặt!";
        }
        strMsg += isValid("<%=txtHoTen.ClientID %>",128,1,spec,1,0,"Họ và tên");
        strMsg += isValidEx(firstChar,1,1,hoten,1,0,"Ký tự đầu tiên của họ và tên");
        strMsg += isValid("<%=txtLanGui.ClientID %>",2,1,number,0,0,"Lần gửi");
        strMsg += isValid("<%=txtDiaChi.ClientID %>",40,1,nonaddress,1,0,"Địa chỉ");
        strMsg += isValid("<%=drpDiaBan.ClientID %>",256,1,spec,1,0,"Địa bàn");
        strMsg += isValid("<%=txtTomTat.ClientID %>",255,1,spec,1,0,"Tóm tắt nội dung");
        
        if ((valDongGui!="") && (!isEmail(valDongGui))){
            strMsg += "\n - " + "Địa chỉ hộp thư đồng gửi không hợp lệ!"
        }
        
        if (strMsg!=""){
            strMsg = strMsg.substr(1);
            alert(strMsg);
            window.returnValue = false;
            return false;
        }
        else{
            document.getElementById('<%=btnOK.ClientID %>').click();
        }
        return false;
    }
    
    
    function OpenPrinter(type)
     {  
        var strVars = "?Type=";
        switch (type) 
        {
            case 0:
                strVars += "PhieuTrinh";
                break;
            case 1:
                strVars += "PhieuChuyen";
                break;
            case 2:
                strVars += "CongVanGiaiQuyet";
                break;
            default:
                strVars += "VanBanApDung";
                break;
        }
        strVars += "&HoTen=" + util.Trim($('#<%=txtHoTen.ClientID %>').val());
        strVars += "&DiaChi=" + util.Trim($('#<%=txtDiaChi.ClientID %>').val());
        strVars += "&NoiDung=" + util.Trim($('#<%=txtTomTat.ClientID %>').val());
        strVars += "&DeXuatYKien=" + util.Trim($('#<%=txtDeXuatYKien.ClientID %>').val());
        strVars += "&SoThuLy=" + util.Trim($('#<%=txtSoThuLy.ClientID %>').val());
        strVars += "&NgayGui=" + util.Trim($('#<%=txtNgayGui.ClientID %>').val());
        strVars += "&YKienLDVP=" + util.Trim($('#<%=txtYKienLDVP.ClientID %>').val());
        strVars += "&YKienLDUBND=" + util.Trim($('#<%=txtYKienLDUBND.ClientID %>').val());       
       
        var strTypeReport = "Reports/PhieuTrinhPhieuChuyenReportView.aspx";
        strFeatures = 'width=800px,height=600px,top=100px,left=100px,titlebar=1,menubar=0,toolbar=0,resizable=1,status=1,scrollbars=1,dependent=yes';
        window.open(strTypeReport + strVars,'_blank',strFeatures);
        return false;
    } 
</script>